home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / flex / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-04  |  26.1 KB  |  1,063 lines

  1. #ifndef lint
  2. char yysccsid[] = "@(#)yaccpar    1.4 (Berkeley) 02/25/90";
  3. #endif
  4. #line 30 "parse.y"
  5.  
  6. #include "flexdef.h"
  7.  
  8. #ifndef lint
  9.  
  10. static char copyright[] =
  11.     "@(#) Copyright (c) 1989 The Regents of the University of California.\n";
  12. static char CR_continuation[] = "@(#) All rights reserved.\n";
  13.  
  14. static char rcsid[] =
  15.     "@(#) $Header: parse.y,v 1.1 90/05/15 13:15:15 neath Exp $ (LBL)";
  16.  
  17. #endif
  18.  
  19. int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, actvp, rulelen;
  20. int trlcontxt, xcluflg, cclsorted, varlength, variable_trail_rule;
  21. char clower();
  22.  
  23. static int madeany = false;  /* whether we've made the '.' character class */
  24. int previous_continued_action;    /* whether the previous rule's action was '|' */
  25.  
  26. #line 27 "y_tab.c"
  27. #define CHAR 257
  28. #define NUMBER 258
  29. #define SECTEND 259
  30. #define SCDECL 260
  31. #define XSCDECL 261
  32. #define WHITESPACE 262
  33. #define NAME 263
  34. #define PREVCCL 264
  35. #define EOF_OP 265
  36. #define YYERRCODE 256
  37. short yylhs[] = {                                        -1,
  38.     0,    1,    2,    2,    2,    3,    6,    6,    7,    7,
  39.     7,    4,    4,    5,    8,    8,    8,    8,    8,    8,
  40.     8,    9,   12,   12,   12,   11,   11,   10,   10,   10,
  41.    14,   13,   13,   15,   15,   15,   15,   15,   15,   15,
  42.    15,   15,   15,   15,   15,   16,   16,   18,   18,   18,
  43.    17,   17,
  44. };
  45. short yylen[] = {                                         2,
  46.     5,    0,    5,    0,    2,    1,    1,    1,    3,    1,
  47.     1,    4,    0,    0,    4,    3,    3,    2,    2,    1,
  48.     1,    3,    3,    1,    1,    1,    0,    3,    2,    1,
  49.     2,    2,    1,    2,    2,    2,    6,    5,    4,    1,
  50.     1,    1,    3,    3,    1,    3,    4,    4,    2,    0,
  51.     2,    0,
  52. };
  53. short yydefred[] = {                                      2,
  54.     0,    0,    0,    0,    5,    6,    7,    8,   13,    0,
  55.    14,    0,    0,   11,   10,    0,   21,   45,   42,   20,
  56.     0,    0,   40,   52,    0,    0,    0,    0,    0,    0,
  57.     0,    0,   41,    0,    3,    0,   25,   24,    0,    0,
  58.     0,   50,    0,   12,   19,    0,    0,   26,    0,   31,
  59.    18,    0,    0,   34,   35,   36,    0,    9,   17,   22,
  60.     0,   51,   43,   44,    0,    0,   46,    0,   16,    0,
  61.     0,   23,   47,    0,   15,    0,   39,   48,    0,   38,
  62.    37,
  63. };
  64. short yydgoto[] = {                                       1,
  65.     2,    4,    9,   11,   13,   10,   16,   27,   28,   29,
  66.    51,   39,   30,   31,   32,   33,   40,   43,
  67. };
  68. short yysindex[] = {                                      0,
  69.     0, -233,   15, -171,    0,    0,    0,    0,    0, -224,
  70.     0, -187,  -32,    0,    0,   -9,    0,    0,    0,    0,
  71.   -28, -185,    0,    0,  -28,  -50,   42,  -30,  -15,  -28,
  72.   -28,   23,    0, -205,    0,  -15,    0,    0,    5,  -29,
  73.    -6,    0,  -86,    0,    0,  -28,  -15,    0,  -28,    0,
  74.     0,   23,  -28,    0,    0,    0, -198,    0,    0,    0,
  75.  -186,    0,    0,    0,  -84,   34,    0,  -15,    0,  -28,
  76.   -22,    0,    0, -177,    0, -110,    0,    0,  -43,    0,
  77.     0,
  78. };
  79. short yyrindex[] = {                                      0,
  80.     0, -165,    0,    0,    0,    0,    0,    0,    0,    0,
  81.     0,    0,   83,    0,    0,    0,    0,    0,    0,    0,
  82.     0,    0,    0,    0,    0,  -82,    0,    0,   75,    7,
  83.     0,  -10,    0,    0,    0,   75,    0,    0,    0,    0,
  84.     0,    0,    0,    0,    0,    0,   75,    0,    0,    0,
  85.     0,   -7,    9,    0,    0,    0,    0,    0,    0,    0,
  86.     0,    0,    0,    0,    0,  -80,    0,   75,    0,   10,
  87.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  88.     0,
  89. };
  90. short yygindex[] = {                                      0,
  91.     0,    0,    0,    0,    0,    0,    0,    0,    0,   47,
  92.     6,    0,   24,    0,   17,    0,    0,   49,
  93. };
  94. #define YYTABLESIZE 257
  95. short yytable[] = {                                      33,
  96.    35,   24,   32,   24,   63,   24,   67,   25,   73,   25,
  97.    50,   25,   49,   23,   80,   23,   30,   23,   29,   28,
  98.    48,   76,    3,   33,    5,   33,   32,   22,   32,   33,
  99.    33,   50,   32,   32,   64,   33,   33,   12,   32,   32,
  100.    50,   59,   30,   42,   29,   28,   52,   30,   61,   29,
  101.    28,   44,   69,   30,   53,   29,   28,   58,   26,   71,
  102.    26,   21,   26,   46,   54,   55,   60,   36,   14,   52,
  103.    37,   41,   70,   75,   47,   15,   72,   38,   74,   78,
  104.    33,   81,    1,   32,   27,   56,   52,    6,    7,    8,
  105.    65,    0,   68,    4,    4,    4,    0,    0,    0,    0,
  106.     0,    0,   77,    0,    0,    0,    0,    0,   49,    0,
  107.     0,    0,    0,   33,    0,    0,   32,   49,    0,    0,
  108.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  109.    30,    0,   29,   28,    0,    0,    0,    0,    0,    0,
  110.     0,    0,    0,    0,    0,   57,    0,   79,    0,    0,
  111.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  112.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  113.    66,    0,   66,    0,   50,    0,   49,    0,    0,    0,
  114.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  115.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  116.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  117.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  118.     0,    0,    0,   17,   18,    0,   18,   62,   18,    0,
  119.     0,   19,   20,   19,   45,   19,    0,    0,    0,    0,
  120.     0,    0,    0,    0,    0,    0,   33,    0,    0,   32,
  121.     0,    0,   34,   33,    0,    0,   32,
  122. };
  123. short yycheck[] = {                                      10,
  124.    10,   34,   10,   34,   34,   34,   93,   40,   93,   40,
  125.    93,   40,   93,   46,  125,   46,   10,   46,   10,   10,
  126.    36,   44,  256,   34,   10,   36,   34,   60,   36,   40,
  127.    41,   47,   40,   41,   41,   46,   47,  262,   46,   47,
  128.    47,   36,   36,   94,   36,   36,   30,   41,   44,   41,
  129.    41,   10,   47,   47,   31,   47,   47,  263,   91,  258,
  130.    91,   94,   91,   94,   42,   43,   62,   21,  256,   53,
  131.   256,   25,   49,   68,   28,  263,  263,  263,   45,  257,
  132.    91,  125,    0,   91,   10,   63,   70,  259,  260,  261,
  133.    42,   -1,   46,  259,  260,  261,   -1,   -1,   -1,   -1,
  134.    -1,   -1,  125,   -1,   -1,   -1,   -1,   -1,  124,   -1,
  135.    -1,   -1,   -1,  124,   -1,   -1,  124,  124,   -1,   -1,
  136.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  137.   124,   -1,  124,  124,   -1,   -1,   -1,   -1,   -1,   -1,
  138.    -1,   -1,   -1,   -1,   -1,  123,   -1,  258,   -1,   -1,
  139.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  140.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  141.   257,   -1,  257,   -1,  257,   -1,  257,   -1,   -1,   -1,
  142.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  143.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  144.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  145.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  146.    -1,   -1,   -1,  256,  257,   -1,  257,  257,  257,   -1,
  147.    -1,  264,  265,  264,  265,  264,   -1,   -1,   -1,   -1,
  148.    -1,   -1,   -1,   -1,   -1,   -1,  257,   -1,   -1,  257,
  149.    -1,   -1,  262,  264,   -1,   -1,  264,
  150. };
  151. #define YYFINAL 1
  152. #ifndef YYDEBUG
  153. #define YYDEBUG 0
  154. #endif
  155. #define YYMAXTOKEN 265
  156. #if YYDEBUG
  157. char *yyname[] = {
  158. "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,
  159. 0,0,0,0,0,0,0,0,0,0,0,"'\"'",0,"'$'",0,0,0,"'('","')'","'*'","'+'","','","'-'",
  160. "'.'","'/'",0,0,0,0,0,0,0,0,0,0,0,0,"'<'",0,"'>'","'?'",0,0,0,0,0,0,0,0,0,0,0,0,
  161. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  162. 0,0,0,0,0,0,0,0,0,0,0,0,0,"'{'","'|'","'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  163. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  164. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  165. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"CHAR",
  166. "NUMBER","SECTEND","SCDECL","XSCDECL","WHITESPACE","NAME","PREVCCL","EOF_OP",
  167. };
  168. char *yyrule[] = {
  169. "$accept : goal",
  170. "goal : initlex sect1 sect1end sect2 initforrule",
  171. "initlex :",
  172. "sect1 : sect1 startconddecl WHITESPACE namelist1 '\\n'",
  173. "sect1 :",
  174. "sect1 : error '\\n'",
  175. "sect1end : SECTEND",
  176. "startconddecl : SCDECL",
  177. "startconddecl : XSCDECL",
  178. "namelist1 : namelist1 WHITESPACE NAME",
  179. "namelist1 : NAME",
  180. "namelist1 : error",
  181. "sect2 : sect2 initforrule flexrule '\\n'",
  182. "sect2 :",
  183. "initforrule :",
  184. "flexrule : scon '^' re eol",
  185. "flexrule : scon re eol",
  186. "flexrule : '^' re eol",
  187. "flexrule : re eol",
  188. "flexrule : scon EOF_OP",
  189. "flexrule : EOF_OP",
  190. "flexrule : error",
  191. "scon : '<' namelist2 '>'",
  192. "namelist2 : namelist2 ',' NAME",
  193. "namelist2 : NAME",
  194. "namelist2 : error",
  195. "eol : '$'",
  196. "eol :",
  197. "re : re '|' series",
  198. "re : re2 series",
  199. "re : series",
  200. "re2 : re '/'",
  201. "series : series singleton",
  202. "series : singleton",
  203. "singleton : singleton '*'",
  204. "singleton : singleton '+'",
  205. "singleton : singleton '?'",
  206. "singleton : singleton '{' NUMBER ',' NUMBER '}'",
  207. "singleton : singleton '{' NUMBER ',' '}'",
  208. "singleton : singleton '{' NUMBER '}'",
  209. "singleton : '.'",
  210. "singleton : fullccl",
  211. "singleton : PREVCCL",
  212. "singleton : '\"' string '\"'",
  213. "singleton : '(' re ')'",
  214. "singleton : CHAR",
  215. "fullccl : '[' ccl ']'",
  216. "fullccl : '[' '^' ccl ']'",
  217. "ccl : ccl CHAR '-' CHAR",
  218. "ccl : ccl CHAR",
  219. "ccl :",
  220. "string : string CHAR",
  221. "string :",
  222. };
  223. #endif
  224. #ifndef YYSTYPE
  225. typedef int YYSTYPE;
  226. #endif
  227. #define yyclearin (yychar=(-1))
  228. #define yyerrok (yyerrflag=0)
  229. #ifndef YYSTACKSIZE
  230. #ifdef YYMAXDEPTH
  231. #define YYSTACKSIZE YYMAXDEPTH
  232. #else
  233. #define YYSTACKSIZE 300
  234. #endif
  235. #endif
  236. int yydebug;
  237. int yynerrs;
  238. int yyerrflag;
  239. int yychar;
  240. short *yyssp;
  241. YYSTYPE *yyvsp;
  242. YYSTYPE yyval;
  243. YYSTYPE yylval;
  244. #define yystacksize YYSTACKSIZE
  245. short yyss[YYSTACKSIZE];
  246. YYSTYPE yyvs[YYSTACKSIZE];
  247. #line 596 "parse.y"
  248.  
  249.  
  250. /* build_eof_action - build the "<<EOF>>" action for the active start
  251.  *                    conditions
  252.  */
  253.  
  254. build_eof_action()
  255.  
  256.     {
  257.     register int i;
  258.  
  259.     for ( i = 1; i <= actvp; ++i )
  260.     {
  261.     if ( sceof[actvsc[i]] )
  262.         lerrsf( "multiple <<EOF>> rules for start condition %s",
  263.             scname[actvsc[i]] );
  264.  
  265.     else
  266.         {
  267.         sceof[actvsc[i]] = true;
  268.         fprintf( temp_action_file, "case YY_STATE_EOF(%s):\n",
  269.              scname[actvsc[i]] );
  270.         }
  271.     }
  272.  
  273.     line_directive_out( temp_action_file );
  274.     }
  275.  
  276.  
  277. /* synerr - report a syntax error
  278.  *
  279.  * synopsis
  280.  *    char str[];
  281.  *    synerr( str );
  282.  */
  283.  
  284. synerr( str )
  285. char str[];
  286.  
  287.     {
  288.     syntaxerror = true;
  289.     fprintf( stderr, "Syntax error at line %d: %s\n", linenum, str );
  290.     }
  291.  
  292.  
  293. /* yyerror - eat up an error message from the parser
  294.  *
  295.  * synopsis
  296.  *    char msg[];
  297.  *    yyerror( msg );
  298.  */
  299.  
  300. yyerror( msg )
  301. char msg[];
  302.  
  303.     {
  304.     }
  305.  
  306.  
  307.  
  308. #line 309 "y_tab.c"
  309. #define YYABORT goto yyabort
  310. #define YYACCEPT goto yyaccept
  311. #define YYERROR goto yyerrlab
  312. int
  313. yyparse()
  314. {
  315.     register int yym, yyn, yystate;
  316. #if YYDEBUG
  317.     register char *yys;
  318.     extern char *getenv();
  319.  
  320.     if (yys = getenv("YYDEBUG"))
  321.     {
  322.         yyn = *yys;
  323.         if (yyn >= '0' && yyn <= '9')
  324.             yydebug = yyn - '0';
  325.     }
  326. #endif
  327.  
  328.     yynerrs = 0;
  329.     yyerrflag = 0;
  330.     yychar = (-1);
  331.  
  332.     yyssp = yyss;
  333.     yyvsp = yyvs;
  334.     *yyssp = yystate = 0;
  335.  
  336. yyloop:
  337.     if (yyn = yydefred[yystate]) goto yyreduce;
  338.     if (yychar < 0)
  339.     {
  340.         if ((yychar = yylex()) < 0) yychar = 0;
  341. #if YYDEBUG
  342.         if (yydebug)
  343.         {
  344.             yys = 0;
  345.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  346.             if (!yys) yys = "illegal-symbol";
  347.             printf("yydebug: state %d, reading %d (%s)\n", yystate,
  348.                     yychar, yys);
  349.         }
  350. #endif
  351.     }
  352.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  353.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  354.     {
  355. #if YYDEBUG
  356.         if (yydebug)
  357.             printf("yydebug: state %d, shifting to state %d\n",
  358.                     yystate, yytable[yyn]);
  359. #endif
  360.         if (yyssp >= yyss + yystacksize - 1)
  361.         {
  362.             goto yyoverflow;
  363.         }
  364.         *++yyssp = yystate = yytable[yyn];
  365.         *++yyvsp = yylval;
  366.         yychar = (-1);
  367.         if (yyerrflag > 0)  --yyerrflag;
  368.         goto yyloop;
  369.     }
  370.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  371.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  372.     {
  373.         yyn = yytable[yyn];
  374.         goto yyreduce;
  375.     }
  376.     if (yyerrflag) goto yyinrecovery;
  377. #ifdef lint
  378.     goto yynewerror;
  379. #endif
  380. yynewerror:
  381.     yyerror("syntax error");
  382. #ifdef lint
  383.     goto yyerrlab;
  384. #endif
  385. yyerrlab:
  386.     ++yynerrs;
  387. yyinrecovery:
  388.     if (yyerrflag < 3)
  389.     {
  390.         yyerrflag = 3;
  391.         for (;;)
  392.         {
  393.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  394.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
  395.             {
  396. #if YYDEBUG
  397.                 if (yydebug)
  398.                     printf("yydebug: state %d, error recovery shifting\
  399.  to state %d\n", *yyssp, yytable[yyn]);
  400. #endif
  401.                 if (yyssp >= yyss + yystacksize - 1)
  402.                 {
  403.                     goto yyoverflow;
  404.                 }
  405.                 *++yyssp = yystate = yytable[yyn];
  406.                 *++yyvsp = yylval;
  407.                 goto yyloop;
  408.             }
  409.             else
  410.             {
  411. #if YYDEBUG
  412.                 if (yydebug)
  413.                     printf("yydebug: error recovery discarding state %d\n",
  414.                             *yyssp);
  415. #endif
  416.                 if (yyssp <= yyss) goto yyabort;
  417.                 --yyssp;
  418.                 --yyvsp;
  419.             }
  420.         }
  421.     }
  422.     else
  423.     {
  424.         if (yychar == 0) goto yyabort;
  425. #if YYDEBUG
  426.         if (yydebug)
  427.         {
  428.             yys = 0;
  429.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  430.             if (!yys) yys = "illegal-symbol";
  431.             printf("yydebug: state %d, error recovery discards token %d (%s)\n",
  432.                     yystate, yychar, yys);
  433.         }
  434. #endif
  435.         yychar = (-1);
  436.         goto yyloop;
  437.     }
  438. yyreduce:
  439. #if YYDEBUG
  440.     if (yydebug)
  441.         printf("yydebug: state %d, reducing by rule %d (%s)\n",
  442.                 yystate, yyn, yyrule[yyn]);
  443. #endif
  444.     yym = yylen[yyn];
  445.     yyval = yyvsp[1-yym];
  446.     switch (yyn)
  447.     {
  448. case 1:
  449. #line 55 "parse.y"
  450. { /* add default rule */
  451.             int def_rule;
  452.  
  453.             pat = cclinit();
  454.             cclnegate( pat );
  455.  
  456.             def_rule = mkstate( -pat );
  457.  
  458.             finish_rule( def_rule, false, 0, 0 );
  459.  
  460.             for ( i = 1; i <= lastsc; ++i )
  461.                 scset[i] = mkbranch( scset[i], def_rule );
  462.  
  463.             if ( spprdflt )
  464.                 fputs( "YY_FATAL_ERROR( \"flex scanner jammed\" )",
  465.                    temp_action_file );
  466.             else
  467.                 fputs( "ECHO", temp_action_file );
  468.  
  469.             fputs( ";\n\tYY_BREAK\n", temp_action_file );
  470.             }
  471. break;
  472. case 2:
  473. #line 79 "parse.y"
  474. {
  475.             /* initialize for processing rules */
  476.  
  477.             /* create default DFA start condition */
  478.             scinstal( "INITIAL", false );
  479.             }
  480. break;
  481. case 5:
  482. #line 90 "parse.y"
  483. { synerr( "unknown error processing section 1" ); }
  484. break;
  485. case 7:
  486. #line 97 "parse.y"
  487. {
  488.             /* these productions are separate from the s1object
  489.              * rule because the semantics must be done before
  490.              * we parse the remainder of an s1object
  491.              */
  492.  
  493.             xcluflg = false;
  494.             }
  495. break;
  496. case 8:
  497. #line 107 "parse.y"
  498. { xcluflg = true; }
  499. break;
  500. case 9:
  501. #line 111 "parse.y"
  502. { scinstal( nmstr, xcluflg ); }
  503. break;
  504. case 10:
  505. #line 114 "parse.y"
  506. { scinstal( nmstr, xcluflg ); }
  507. break;
  508. case 11:
  509. #line 117 "parse.y"
  510. { synerr( "bad start condition list" ); }
  511. break;
  512. case 14:
  513. #line 125 "parse.y"
  514. {
  515.             /* initialize for a parse of one rule */
  516.             trlcontxt = variable_trail_rule = varlength = false;
  517.             trailcnt = headcnt = rulelen = 0;
  518.             current_state_type = STATE_NORMAL;
  519.             previous_continued_action = continued_action;
  520.             new_rule();
  521.             }
  522. break;
  523. case 15:
  524. #line 136 "parse.y"
  525. {
  526.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  527.             finish_rule( pat, variable_trail_rule,
  528.                      headcnt, trailcnt );
  529.  
  530.             for ( i = 1; i <= actvp; ++i )
  531.                 scbol[actvsc[i]] =
  532.                 mkbranch( scbol[actvsc[i]], pat );
  533.  
  534.             if ( ! bol_needed )
  535.                 {
  536.                 bol_needed = true;
  537.  
  538.                 if ( performance_report )
  539.                 fprintf( stderr,
  540.             "'^' operator results in sub-optimal performance\n" );
  541.                 }
  542.             }
  543. break;
  544. case 16:
  545. #line 156 "parse.y"
  546. {
  547.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  548.             finish_rule( pat, variable_trail_rule,
  549.                      headcnt, trailcnt );
  550.  
  551.             for ( i = 1; i <= actvp; ++i )
  552.                 scset[actvsc[i]] = 
  553.                 mkbranch( scset[actvsc[i]], pat );
  554.             }
  555. break;
  556. case 17:
  557. #line 167 "parse.y"
  558. {
  559.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  560.             finish_rule( pat, variable_trail_rule,
  561.                      headcnt, trailcnt );
  562.  
  563.             /* add to all non-exclusive start conditions,
  564.              * including the default (0) start condition
  565.              */
  566.  
  567.             for ( i = 1; i <= lastsc; ++i )
  568.                 if ( ! scxclu[i] )
  569.                 scbol[i] = mkbranch( scbol[i], pat );
  570.  
  571.             if ( ! bol_needed )
  572.                 {
  573.                 bol_needed = true;
  574.  
  575.                 if ( performance_report )
  576.                 fprintf( stderr,
  577.             "'^' operator results in sub-optimal performance\n" );
  578.                 }
  579.             }
  580. break;
  581. case 18:
  582. #line 191 "parse.y"
  583. {
  584.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  585.             finish_rule( pat, variable_trail_rule,
  586.                      headcnt, trailcnt );
  587.  
  588.             for ( i = 1; i <= lastsc; ++i )
  589.                 if ( ! scxclu[i] )
  590.                 scset[i] = mkbranch( scset[i], pat );
  591.             }
  592. break;
  593. case 19:
  594. #line 202 "parse.y"
  595. { build_eof_action(); }
  596. break;
  597. case 20:
  598. #line 205 "parse.y"
  599. {
  600.             /* this EOF applies only to the INITIAL start cond. */
  601.             actvsc[actvp = 1] = 1;
  602.             build_eof_action();
  603.             }
  604. break;
  605. case 21:
  606. #line 212 "parse.y"
  607. { synerr( "unrecognized rule" ); }
  608. break;
  609. case 23:
  610. #line 219 "parse.y"
  611. {
  612.             if ( (scnum = sclookup( nmstr )) == 0 )
  613.                 lerrsf( "undeclared start condition %s", nmstr );
  614.  
  615.             else
  616.                 actvsc[++actvp] = scnum;
  617.             }
  618. break;
  619. case 24:
  620. #line 228 "parse.y"
  621. {
  622.             if ( (scnum = sclookup( nmstr )) == 0 )
  623.                 lerrsf( "undeclared start condition %s", nmstr );
  624.             else
  625.                 actvsc[actvp = 1] = scnum;
  626.             }
  627. break;
  628. case 25:
  629. #line 236 "parse.y"
  630. { synerr( "bad start condition list" ); }
  631. break;
  632. case 26:
  633. #line 240 "parse.y"
  634. {
  635.             if ( trlcontxt )
  636.                 {
  637.                 synerr( "trailing context used twice" );
  638.                 yyval  = mkstate( SYM_EPSILON );
  639.                 }
  640.             else
  641.                 {
  642.                 trlcontxt = true;
  643.  
  644.                 if ( ! varlength )
  645.                 headcnt = rulelen;
  646.  
  647.                 ++rulelen;
  648.                 trailcnt = 1;
  649.  
  650.                 eps = mkstate( SYM_EPSILON );
  651.                 yyval  = link_machines( eps, mkstate( '\n' ) );
  652.                 }
  653.             }
  654. break;
  655. case 27:
  656. #line 262 "parse.y"
  657. {
  658.                 yyval  = mkstate( SYM_EPSILON );
  659.  
  660.             if ( trlcontxt )
  661.                 {
  662.                 if ( varlength && headcnt == 0 )
  663.                 /* both head and trail are variable-length */
  664.                 variable_trail_rule = true;
  665.                 else
  666.                 trailcnt = rulelen;
  667.                 }
  668.                 }
  669. break;
  670. case 28:
  671. #line 277 "parse.y"
  672. {
  673.             varlength = true;
  674.  
  675.             yyval  = mkor( yyvsp[-2], yyvsp[0] );
  676.             }
  677. break;
  678. case 29:
  679. #line 284 "parse.y"
  680. {
  681.             if ( transchar[lastst[yyvsp[0]]] != SYM_EPSILON )
  682.                 /* provide final transition \now/ so it
  683.                  * will be marked as a trailing context
  684.                  * state
  685.                  */
  686.                 yyvsp[0] = link_machines( yyvsp[0], mkstate( SYM_EPSILON ) );
  687.  
  688.             mark_beginning_as_normal( yyvsp[0] );
  689.             current_state_type = STATE_NORMAL;
  690.  
  691.             if ( previous_continued_action )
  692.                 {
  693.                 /* we need to treat this as variable trailing
  694.                  * context so that the backup does not happen
  695.                  * in the action but before the action switch
  696.                  * statement.  If the backup happens in the
  697.                  * action, then the rules "falling into" this
  698.                  * one's action will *also* do the backup,
  699.                  * erroneously.
  700.                  */
  701.                 if ( ! varlength || headcnt != 0 )
  702.                 {
  703.                 fprintf( stderr,
  704.     "flex: warning - trailing context rule at line %d made variable because\n",
  705.                      linenum );
  706.                 fprintf( stderr,
  707.                      "      of preceding '|' action\n" );
  708.                 }
  709.  
  710.                 /* mark as variable */
  711.                 varlength = true;
  712.                 headcnt = 0;
  713.                 }
  714.  
  715.             if ( varlength && headcnt == 0 )
  716.                 { /* variable trailing context rule */
  717.                 /* mark the first part of the rule as the accepting
  718.                  * "head" part of a trailing context rule
  719.                  */
  720.                 /* by the way, we didn't do this at the beginning
  721.                  * of this production because back then
  722.                  * current_state_type was set up for a trail
  723.                  * rule, and add_accept() can create a new
  724.                  * state ...
  725.                  */
  726.                 add_accept( yyvsp[-1], num_rules | YY_TRAILING_HEAD_MASK );
  727.                 }
  728.  
  729.             yyval  = link_machines( yyvsp[-1], yyvsp[0] );
  730.             }
  731. break;
  732. case 30:
  733. #line 337 "parse.y"
  734. { yyval  = yyvsp[0]; }
  735. break;
  736. case 31:
  737. #line 342 "parse.y"
  738. {
  739.             /* this rule is separate from the others for "re" so
  740.              * that the reduction will occur before the trailing
  741.              * series is parsed
  742.              */
  743.  
  744.             if ( trlcontxt )
  745.                 synerr( "trailing context used twice" );
  746.             else
  747.                 trlcontxt = true;
  748.  
  749.             if ( varlength )
  750.                 /* we hope the trailing context is fixed-length */
  751.                 varlength = false;
  752.             else
  753.                 headcnt = rulelen;
  754.  
  755.             rulelen = 0;
  756.  
  757.             current_state_type = STATE_TRAILING_CONTEXT;
  758.             yyval  = yyvsp[-1];
  759.             }
  760. break;
  761. case 32:
  762. #line 367 "parse.y"
  763. {
  764.             /* this is where concatenation of adjacent patterns
  765.              * gets done
  766.              */
  767.             yyval  = link_machines( yyvsp[-1], yyvsp[0] );
  768.             }
  769. break;
  770. case 33:
  771. #line 375 "parse.y"
  772. { yyval  = yyvsp[0]; }
  773. break;
  774. case 34:
  775. #line 379 "parse.y"
  776. {
  777.             varlength = true;
  778.  
  779.             yyval  = mkclos( yyvsp[-1] );
  780.             }
  781. break;
  782. case 35:
  783. #line 386 "parse.y"
  784. {
  785.             varlength = true;
  786.  
  787.             yyval  = mkposcl( yyvsp[-1] );
  788.             }
  789. break;
  790. case 36:
  791. #line 393 "parse.y"
  792. {
  793.             varlength = true;
  794.  
  795.             yyval  = mkopt( yyvsp[-1] );
  796.             }
  797. break;
  798. case 37:
  799. #line 400 "parse.y"
  800. {
  801.             varlength = true;
  802.  
  803.             if ( yyvsp[-3] > yyvsp[-1] || yyvsp[-3] < 0 )
  804.                 {
  805.                 synerr( "bad iteration values" );
  806.                 yyval  = yyvsp[-5];
  807.                 }
  808.             else
  809.                 {
  810.                 if ( yyvsp[-3] == 0 )
  811.                 yyval  = mkopt( mkrep( yyvsp[-5], yyvsp[-3], yyvsp[-1] ) );
  812.                 else
  813.                 yyval  = mkrep( yyvsp[-5], yyvsp[-3], yyvsp[-1] );
  814.                 }
  815.             }
  816. break;
  817. case 38:
  818. #line 418 "parse.y"
  819. {
  820.             varlength = true;
  821.  
  822.             if ( yyvsp[-2] <= 0 )
  823.                 {
  824.                 synerr( "iteration value must be positive" );
  825.                 yyval  = yyvsp[-4];
  826.                 }
  827.  
  828.             else
  829.                 yyval  = mkrep( yyvsp[-4], yyvsp[-2], INFINITY );
  830.             }
  831. break;
  832. case 39:
  833. #line 432 "parse.y"
  834. {
  835.             /* the singleton could be something like "(foo)",
  836.              * in which case we have no idea what its length
  837.              * is, so we punt here.
  838.              */
  839.             varlength = true;
  840.  
  841.             if ( yyvsp[-1] <= 0 )
  842.                 {
  843.                 synerr( "iteration value must be positive" );
  844.                 yyval  = yyvsp[-3];
  845.                 }
  846.  
  847.             else
  848.                 yyval  = link_machines( yyvsp[-3], copysingl( yyvsp[-3], yyvsp[-1] - 1 ) );
  849.             }
  850. break;
  851. case 40:
  852. #line 450 "parse.y"
  853. {
  854.             if ( ! madeany )
  855.                 {
  856.                 /* create the '.' character class */
  857.                 anyccl = cclinit();
  858.                 ccladd( anyccl, '\n' );
  859.                 cclnegate( anyccl );
  860.  
  861.                 if ( useecs )
  862.                 mkeccl( ccltbl + cclmap[anyccl],
  863.                     ccllen[anyccl], nextecm,
  864.                     ecgroup, CSIZE );
  865.                 
  866.                 madeany = true;
  867.                 }
  868.  
  869.             ++rulelen;
  870.  
  871.             yyval  = mkstate( -anyccl );
  872.             }
  873. break;
  874. case 41:
  875. #line 472 "parse.y"
  876. {
  877.             if ( ! cclsorted )
  878.                 /* sort characters for fast searching.  We use a
  879.                  * shell sort since this list could be large.
  880.                  */
  881.                 cshell( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]] );
  882.  
  883.             if ( useecs )
  884.                 mkeccl( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]],
  885.                     nextecm, ecgroup, CSIZE );
  886.                      
  887.             ++rulelen;
  888.  
  889.             yyval  = mkstate( -yyvsp[0] );
  890.             }
  891. break;
  892. case 42:
  893. #line 489 "parse.y"
  894. {
  895.             ++rulelen;
  896.  
  897.             yyval  = mkstate( -yyvsp[0] );
  898.             }
  899. break;
  900. case 43:
  901. #line 496 "parse.y"
  902. { yyval  = yyvsp[-1]; }
  903. break;
  904. case 44:
  905. #line 499 "parse.y"
  906. { yyval  = yyvsp[-1]; }
  907. break;
  908. case 45:
  909. #line 502 "parse.y"
  910. {
  911.             ++rulelen;
  912.  
  913.             if ( yyvsp[0] == '\0' )
  914.                 synerr( "null in rule" );
  915.  
  916.             if ( caseins && yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  917.                 yyvsp[0] = clower( yyvsp[0] );
  918.  
  919.             yyval  = mkstate( yyvsp[0] );
  920.             }
  921. break;
  922. case 46:
  923. #line 516 "parse.y"
  924. { yyval  = yyvsp[-1]; }
  925. break;
  926. case 47:
  927. #line 519 "parse.y"
  928. {
  929.             /* *Sigh* - to be compatible Unix lex, negated ccls
  930.              * match newlines
  931.              */
  932. #ifdef NOTDEF
  933.             ccladd( yyvsp[-1], '\n' ); /* negated ccls don't match '\n' */
  934.             cclsorted = false; /* because we added the newline */
  935. #endif
  936.             cclnegate( yyvsp[-1] );
  937.             yyval  = yyvsp[-1];
  938.             }
  939. break;
  940. case 48:
  941. #line 533 "parse.y"
  942. {
  943.             if ( yyvsp[-2] > yyvsp[0] )
  944.                 synerr( "negative range in character class" );
  945.  
  946.             else
  947.                 {
  948.                 if ( caseins )
  949.                 {
  950.                 if ( yyvsp[-2] >= 'A' && yyvsp[-2] <= 'Z' )
  951.                     yyvsp[-2] = clower( yyvsp[-2] );
  952.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  953.                     yyvsp[0] = clower( yyvsp[0] );
  954.                 }
  955.  
  956.                 for ( i = yyvsp[-2]; i <= yyvsp[0]; ++i )
  957.                     ccladd( yyvsp[-3], i );
  958.  
  959.                 /* keep track if this ccl is staying in alphabetical
  960.                  * order
  961.                  */
  962.                 cclsorted = cclsorted && (yyvsp[-2] > lastchar);
  963.                 lastchar = yyvsp[0];
  964.                 }
  965.             
  966.             yyval  = yyvsp[-3];
  967.             }
  968. break;
  969. case 49:
  970. #line 561 "parse.y"
  971. {
  972.             if ( caseins )
  973.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  974.                 yyvsp[0] = clower( yyvsp[0] );
  975.  
  976.             ccladd( yyvsp[-1], yyvsp[0] );
  977.             cclsorted = cclsorted && (yyvsp[0] > lastchar);
  978.             lastchar = yyvsp[0];
  979.             yyval  = yyvsp[-1];
  980.             }
  981. break;
  982. case 50:
  983. #line 573 "parse.y"
  984. {
  985.             cclsorted = true;
  986.             lastchar = 0;
  987.             yyval  = cclinit();
  988.             }
  989. break;
  990. case 51:
  991. #line 581 "parse.y"
  992. {
  993.             if ( caseins )
  994.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  995.                 yyvsp[0] = clower( yyvsp[0] );
  996.  
  997.             ++rulelen;
  998.  
  999.             yyval  = link_machines( yyvsp[-1], mkstate( yyvsp[0] ) );
  1000.             }
  1001. break;
  1002. case 52:
  1003. #line 592 "parse.y"
  1004. { yyval  = mkstate( SYM_EPSILON ); }
  1005. break;
  1006. #line 1007 "y_tab.c"
  1007.     }
  1008.     yyssp -= yym;
  1009.     yystate = *yyssp;
  1010.     yyvsp -= yym;
  1011.     yym = yylhs[yyn];
  1012.     if (yystate == 0 && yym == 0)
  1013.     {
  1014. #ifdef YYDEBUG
  1015.         if (yydebug)
  1016.             printf("yydebug: after reduction, shifting from state 0 to\
  1017.  state %d\n", YYFINAL);
  1018. #endif
  1019.         yystate = YYFINAL;
  1020.         *++yyssp = YYFINAL;
  1021.         *++yyvsp = yyval;
  1022.         if (yychar < 0)
  1023.         {
  1024.             if ((yychar = yylex()) < 0) yychar = 0;
  1025. #if YYDEBUG
  1026.             if (yydebug)
  1027.             {
  1028.                 yys = 0;
  1029.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1030.                 if (!yys) yys = "illegal-symbol";
  1031.                 printf("yydebug: state %d, reading %d (%s)\n",
  1032.                         YYFINAL, yychar, yys);
  1033.             }
  1034. #endif
  1035.         }
  1036.         if (yychar == 0) goto yyaccept;
  1037.         goto yyloop;
  1038.     }
  1039.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  1040.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  1041.         yystate = yytable[yyn];
  1042.     else
  1043.         yystate = yydgoto[yym];
  1044. #ifdef YYDEBUG
  1045.     if (yydebug)
  1046.         printf("yydebug: after reduction, shifting from state %d \
  1047. to state %d\n", *yyssp, yystate);
  1048. #endif
  1049.     if (yyssp >= yyss + yystacksize - 1)
  1050.     {
  1051.         goto yyoverflow;
  1052.     }
  1053.     *++yyssp = yystate;
  1054.     *++yyvsp = yyval;
  1055.     goto yyloop;
  1056. yyoverflow:
  1057.     yyerror("yacc stack overflow");
  1058. yyabort:
  1059.     return (1);
  1060. yyaccept:
  1061.     return (0);
  1062. }
  1063.